package com.camel.network.controller;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.nacos.client.naming.net.HttpClient;
import com.camel.core.entity.Result;
import com.camel.core.utils.ResultUtil;
import com.camel.network.utils.HttpUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.reactive.function.BodyInserter;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author 86183
 */
@RequestMapping("/tasks")
@RestController
public class AutoCallController {

    /**
     * 查询外呼计划
     * @param params
     * @return
     */
    @PostMapping
    public Result index(@RequestBody JSONObject params) {
        JSONObject json = (JSONObject) HttpUtils.post(params, "tj.svdata.cn", "/yscrm/20150101/query/gettask.json");
        return ResultUtil.success(json.getJSONArray("body"));
    }

    /**
     * 创建外呼计划
     * @param params
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody JSONObject params) {
        JSONObject post = (JSONObject) HttpUtils.post(params, "tj.svdata.cn", "/yscrm/20150101/setting/createtask.json");
        if(post.get("statuscode").equals("000000")) {
            return ResultUtil.success();
        } else {
            return ResultUtil.error(500, "保存任务失败");
        }
    }

    @PostMapping("/del")
    public Result del(@RequestBody JSONObject params) {
        JSONObject post = (JSONObject) HttpUtils.post(params, "tj.svdata.cn", "/yscrm/20150101/setting/deletetask.json");
        if(post.get("statuscode").equals("000000")) {
            return ResultUtil.success();
        } else {
            return ResultUtil.error(500, "删除任务失败");
        }
    }

    @PostMapping("/update")
    public Result update(@RequestBody JSONObject params) {
        JSONObject post = (JSONObject) HttpUtils.post(params, "tj.svdata.cn", "/yscrm/20150101/setting/settaskconfig.json");
        if(post.get("statuscode").equals("000000")) {
            return ResultUtil.success();
        } else {
            return ResultUtil.error(500, "修改任务参数失败");
        }
    }
}
